* ============================================================================
* ROBUSTNESS CHECKS FOR STATISTICAL RESULTS APPEARING IN CHAPTER 7
* STATA  
* Stata do-file, Robustness tests for Chapter 7, Mark R. Beissinger, 
*    The Revolutionary City  
version 14
clear all
set more off
log using Robustnesstestfiles\Logfiles\robustnesstestschapter7.log, replace
* =============================================================================
* Robustness checks for results reported in Chapter 7  
* Author: Mark R. Beissinger  
* Date:  January 2022  
* Princeton, NJ 
* =============================================================================
* BEFORE RUNNING, YOU MUST SET THE DEFAULT PATH FOR WHERE THE DATA
*   FILES RESIDE
* ============================================================================
* The following datafiles are used in this chapter:
*   Monitoring surveys (Ukraine)--monitoring20052014engmerged.dta
*   KIIS survey (Ukraine)--mohyla.orangerev.dta
*   2011 Arab Barometer--Tunisia and Egypt--fullarabbarom2.dta
*   NOTE: The Gallup data cited in chapter are not available for replication; readers 
*         interested in these data must consult with the Gallup Organization directly
* =============================================================================
* Before running, download the following packages for STATA:
* checkrob from http://fmwww.bc.edu/RePEc/bocode/c
* spost_13.ado from https://jslsoc.sitehost.iu.edu/spost13.htm for Brant test
* smhsiao module from http://fmwww.bc.edu/RePEc/bocode/s
* collin from https://stats.oarc.ucla.edu/stata/ado/analysis/
* =============================================================================
* The following output is generated by these robustness tests:
*	Robustnesstestfiles\Logfiles\robustnesstestschapter7.log
*	Excel file with the reconfigured results of checkrob tests
*		Robustnesstestfiles\Outputfiles\checkrob.results.chapter7.xlsx
* =============================================================================


* =================================================================
* TESTING BASE MODELS FOR PROPORTIONAL ODDS ASSUMPTION--BRANT TEST
* =================================================================

* Ukraine 2005
clear
use monitoring20052014engmerged.dta
* Testing the proportional odds assumption of ordered logit on gender and age base model
ologit partic5a gender newage if EVA_vers=="yr2005", or
brant, detail
* 	RESULT:  Test failed--must use multinomial logit

* Ukraine 2014
ologit partic5a gender newage if EVA_vers=="yr2014", or
brant, detail
* 	RESULT:  Test failed--must use multinomial logit

* Egyptian Revolution
clear
use fullarabbarom2.dta
ologit egpartic5 gender newage if country==2, or
brant, detail
* 	RESULT:  Test failed--must use multinomial logit

* Tunisian Revolution
ologit tpartic4 gender newage if country==10, or
brant, detail
* 	RESULT:  Test failed--must use multinomial logit

* ======================================================
* TESTING BASE MODELS FOR IIA ASSUMPTION--HAUSMAN TESTS
* ======================================================
* Ukraine data
clear
use monitoring20052014engmerged.dta

* UKRAINE 2005 DATA
quietly: mlogit partic5a gender newage if EVA_vers=="yr2005", rrr b(3)
estimates store basemod
* Test excluding 2
quietly: mlogit partic5a gender newage if EVA_vers=="yr2005" & partic5a~=2, rrr b(3)
estimates store basemodno2
hausman basemodno2 basemod, alleqs constant
*  RESULT:  PASSED
* Test excluding 4
quietly: mlogit partic5a gender newage if EVA_vers=="yr2005" & partic5a~=4, rrr b(3)
estimates store basemodno4
hausman basemodno4 basemod, alleqs constant
*  RESULT:  PASSED
* Test excluding 5
quietly: mlogit partic5a gender newage if EVA_vers=="yr2005" & partic5a~=5, rrr b(3)
estimates store basemodno5
hausman basemodno5 basemod, alleqs constant
*  RESULT:  PASSED
* Test excluding 3, with base 4
quietly: mlogit partic5a gender newage if EVA_vers=="yr2005", rrr b(4)
estimates store altbasemod
quietly: mlogit partic5a gender newage if EVA_vers=="yr2005" & partic5a~=3, rrr b(4)
estimates store altbasemodno3
hausman altbasemodno3 altbasemod, alleqs constant
*  RESULT:  PASSED
drop _est_basemod _est_basemodno2 _est_basemodno4 _est_basemodno5 _est_altbasemod _est_altbasemodno3

* UKRAINE 2014 DATA
quietly: mlogit partic5a gender newage if EVA_vers=="yr2014", rrr b(3)
estimates store basemod
* Test excluding 2
quietly: mlogit partic5a gender newage if EVA_vers=="yr2014" & partic5a~=2, rrr b(3)
estimates store basemodno2
hausman basemodno2 basemod, alleqs constant
*  RESULT:  PASSED
* Test excluding 4
quietly: mlogit partic5a gender newage if EVA_vers=="yr2014" & partic5a~=4, rrr b(3)
estimates store basemodno4
hausman basemodno4 basemod, alleqs constant
*  RESULT:  PASSED
* Test excluding 5
quietly: mlogit partic5a gender newage if EVA_vers=="yr2014" & partic5a~=5, rrr b(3)
estimates store basemodno5
hausman basemodno5 basemod, alleqs constant
*  RESULT:  PASSED
* Test excluding 3, with base 4
quietly: mlogit partic5a gender newage if EVA_vers=="yr2014", rrr b(4)
estimates store altbasemod
quietly: mlogit partic5a gender newage if EVA_vers=="yr2014" & partic5a~=3, rrr b(4)
estimates store altbasemodno3
hausman altbasemodno3 altbasemod, alleqs constant
*  RESULT:  PASSED
drop _est_basemod _est_basemodno2 _est_basemodno4 _est_basemodno5 _est_altbasemod _est_altbasemodno3

* Egyptian and Tunisian data
clear
use fullarabbarom2.dta

* EGYPTIAN REVOLUTION
quietly: mlogit egpartic5 gender newage if country==2, rrr b(3)
estimates store basemod
* Test excluding 2
quietly: mlogit egpartic5 gender newage if country==2 & egpartic5~=2, rrr b(3)
estimates store basemodno2
hausman basemodno2 basemod, alleqs constant
* RESULT:  PASSED
* Test excluding 4
quietly: mlogit egpartic5 gender newage if country==2 & egpartic5~=4, rrr b(3)
estimates store basemodno4
hausman basemodno4 basemod, alleqs constant
* RESULT:  PASSED
* Test excluding 5
quietly: mlogit egpartic5 gender newage if country==2 & egpartic5~=5, rrr b(3)
estimates store basemodno5
hausman basemodno5 basemod, alleqs constant
* RESULT:  PASSED
* Test excluding 3 (with base 4)
quietly: mlogit egpartic5 gender newage if country==2, rrr b(4)
estimates store altbasemod
quietly: mlogit egpartic5 gender newage if country==2 & egpartic5~=3, rrr b(4)
estimates store altbasemodno3
hausman altbasemodno3 altbasemod, alleqs constant
* RESULT:  PASSED
drop _est_basemod _est_basemodno2 _est_basemodno4 _est_basemodno5 _est_altbasemod _est_altbasemodno3

* TUNISIAN REVOLUTION
quietly: mlogit tpartic4 gender newage if country==10, rrr b(2)
estimates store basemod
* Test excluding 3
* quietly: mlogit tpartic4 gender newage if country==10 & tpartic4~=3, rrr b(2)
* estimates store basemodno3
* hausman basemodno3 basemod, alleqs constant
* Failed to meet the asymptotic assumptions of the Hausman test
* Must use suest
* Suest test
quietly: mlogit tpartic4 gender newage if country==10, rrr b(2)
estimates store m1
quietly: mlogit tpartic4 gender newage if country==10 & tpartic4~=3, rrr b(2)
estimates store m3
suest m1 m3, noomitted
test [m1_Participate = m3_Participate], cons
* RESULT:  PASSED
* Test excluding 4
quietly: mlogit tpartic4 gender newage if country==10 & tpartic4~=4, rrr b(2)
estimates store basemodno4
hausman basemodno4 basemod, alleqs constant
* RESULT:  PASSED
* Test excluding 2 (with base 3)
quietly: mlogit tpartic4 gender newage if country==10, rrr b(3)
estimates store altbasemod
quietly: mlogit tpartic4 gender newage if country==10 & tpartic4~=2, rrr b(3)
estimates store altbasemodno2
hausman altbasemodno2 altbasemod, alleqs constant
* RESULT:  PASSED
drop _est_basemod _est_basemodno4 _est_altbasemod _est_altbasemodno2 _est_m1 _est_m3

* ==========================================================
* TESTING BASE MODELS FOR IIA ASSUMPTION--SMALL-HSIAO TESTS
* ==========================================================
* set seed to randomly generated number (number previously generated by runiformint(1000000, 9999999))
* number given here for replicability
set seed 2667533

* UKRAINE DATA
clear
use monitoring20052014engmerged.dta
* Generated two randomly selected groups--group2005 and group2014--for use in Small-Hsiao tests
* gen group2005=rbinomial(1, 0.5) if EVA_vers=="yr2005"
* gen group2014=rbinomial(1, 0.5) if EVA_vers=="yr2014"
* Saved groups for replication
* Performed Small-Hsiao test on 5-part dependent variable for 2005 sample
smhsiao partic5a age gender if EVA_vers=="yr2005", elim(1) samp(group2005)
smhsiao partic5a age gender if EVA_vers=="yr2005", elim(2) samp(group2005)
smhsiao partic5a age gender if EVA_vers=="yr2005", elim(3) samp(group2005)
smhsiao partic5a age gender if EVA_vers=="yr2005", elim(4) samp(group2005)
smhsiao partic5a age gender if EVA_vers=="yr2005", elim(5) samp(group2005)
* RESULT:  Passed
* Performed Small-Hsiao test on 5-part dependent variable for 2014 sample
smhsiao partic5a age gender if EVA_vers=="yr2014", elim(1) samp(group2014)
smhsiao partic5a age gender if EVA_vers=="yr2014", elim(2) samp(group2014)
smhsiao partic5a age gender if EVA_vers=="yr2014", elim(3) samp(group2014)
smhsiao partic5a age gender if EVA_vers=="yr2014", elim(4) samp(group2014)
smhsiao partic5a age gender if EVA_vers=="yr2014", elim(5) samp(group2014)
* RESULT:  Passed
 
* ARAB BAROMETER DATA
clear
use fullarabbarom2.dta
* Small-Hsiao tests
* set seed to randomly generated number (number generated by runiformint(1000000, 9999999))
set seed 2667533
* Generated two randomly selected groups--groupeg and grouptu--for use in Small-Hsiao tests
* gen groupeg=rbinomial(1, 0.5) if country==2
* gen grouptu=rbinomial(1, 0.5) if country==10
* Saved groups for replication
* Performed Small-Hsiao test on 5-part dependent variable for Egyptian sample
smhsiao egpartic5 gender newage if country==2, elim(1) samp(groupeg)
smhsiao egpartic5 gender newage if country==2, elim(2) samp(groupeg)
smhsiao egpartic5 gender newage if country==2, elim(3) samp(groupeg)
smhsiao egpartic5 gender newage if country==2, elim(4) samp(groupeg)
smhsiao egpartic5 gender newage if country==2, elim(5) samp(groupeg)
* RESULT:  Passed
* Performed Small-Hsiao test on 4-part dependent variable for Tunisian sample
smhsiao tpartic4 gender newage if country==10, elim(1) samp(grouptu)
smhsiao tpartic4 gender newage if country==10, elim(2) samp(grouptu)
smhsiao tpartic4 gender newage if country==10, elim(3) samp(grouptu)
smhsiao tpartic4 gender newage if country==10, elim(4) samp(grouptu)
* RESULT:  Passed

* ===================================================================
* ROBUSTNESS TESTS FOR FIGURE 7.9: PARTICIPATION BY LANGUAGE USE AT 
*	HOME (UKRAINE ONLY)
* ===================================================================
* Ukraine data
clear
use monitoring20052014engmerged.dta
* Multinomial logit, but examining only the participation portion of the regression
* Orange Revolution
* checkrob command
* checkrob 2 3 ch7fig7_9a.txt: mlogit partic5a gender newage edulevel consumergoods ukrspeakathome if version==0, rrr
* 	Reworked results can be found in the Excel file checkrob.results.chapter7.xlsx,
*		under the Robustnesstests/Outputfiles directory
*	RESULT:  All patterns of significance stable (with exception of edulevel, which is insignificant when consumergoods included but ukrspeakathome not included); all signs stable
* Robust standard errors
mlogit partic5a  gender newage edulevel consumergoods ukrspeakathome  if EVA_vers=="yr2005", rrr vce(robust)
*	RESULT:  No changes
* Bootstrapped standard errors
mlogit partic5a  gender newage edulevel consumergoods ukrspeakathome if EVA_vers=="yr2005", rrr vce(bootstrap, bca seed(1234) rep(1000))
estat bootstrap, all
* 	RESULT:  No changes
* Testing for multicollinearity
collin  gender newage edulevel consumergoods ukrspeakathome if EVA_vers=="yr2005"
*	RESULT:  tolerances are all > .5

* Euromaidan Revolution
* checkrob command
* checkrob 2 3 ch7fig7_9b.txt: mlogit partic5a gender newage edulevel consumergoods ukrspeakathome if version==1, rrr
* 	Reworked results can be found in the Excel file checkrob.results.chapter7.xlsx,
*		under the Robustnesstests/Outputfiles directory
*	RESULT:  All patterns of significance stable (with exception of edulevel, which is marginally significant at the .10 level when consumergoods included but ukrspeakathome not included); all signs stable
* Robust standard errors
mlogit partic5a  gender newage edulevel consumergoods ukrspeakathome  if EVA_vers=="yr2014", rrr vce(robust)
*	RESULT:  No changes
* Bootstrapped standard errors
mlogit partic5a  gender newage edulevel consumergoods ukrspeakathome if EVA_vers=="yr2014", rrr vce(bootstrap, bca seed(1234) rep(1000))
estat bootstrap, all
* 	RESULT:  No changes
* Testing for multicollinearity
collin  gender newage edulevel consumergoods ukrspeakathome if EVA_vers=="yr2014"
*	RESULT:  tolerances are all > .5


* =================================================================
* ROBUSTNESS TESTS FOR FIGURE 7.10: RELIGIOUS PRACTICE IN TUNISIAN 
*		AND EGYPTIANS REVOLUTIONS
* =================================================================
clear
use fullarabbarom2.dta
* Egyptian Revolution
* checkrob command
* checkrob 1 3 ch7fig7_10a.txt: mlogit egpartic5 gender newage religscale christian if country==2 [pw=WT], rrr b(3)
* 	Reworked results can be found in the Excel file checkrob.results.chapter7.xlsx,
*		under the Robustnesstests/Outputfiles directory
*	RESULT:  All patterns of significance stable (with exception of religscale, which is significant at the .10 level when newage is excluded); all signs stable; christian is statistically insignificant
* Robust standard errors
mlogit egpartic5 gender newage  religscale christian if country==2 [pw=WT], rrr b(3) vce(robust)
*	RESULT:  No changes
* Bootstrapped standard errors
mlogit egpartic5 gender newage  religscale christian if country==2, rrr b(3) vce(bootstrap, bca seed(1234) rep(1000))
estat bootstrap, all
* 	RESULT:  No changes
* Testing for multicollinearity
collin gender newage  religscale christian if country==2
*	RESULT:  tolerances are all > .5
* Tunisian Revolution
* checkrob command
* checkrob 1 2 ch7fig7_10b.txt: mlogit tpartic4 gender newage religscale if country==10 [pw=WT], rrr b(2)
* 	Reworked results can be found in the Excel file checkrob.results.chapter7.xlsx,
*		under the Robustnesstests/Outputfiles directory
*	RESULT:  All patterns of significance stable (with exception of religscale, which is insignificant when newage is excluded); all signs stable
* Robust standard errors
mlogit tpartic4 gender newage religscale if country==10 [pw=WT], rrr b(2) vce(robust)
*	RESULT:  No changes
* Bootstrapped standard errors
mlogit tpartic4 gender newage religscale if country==10, rrr b(2) vce(bootstrap, bca seed(1234) rep(1000))
estat bootstrap, all
* 	RESULT:  No changes
* Testing for multicollinearity
collin gender newage  religscale if country==10
*	RESULT:  tolerances are all > .5

* =============================================================================
* ROBUSTNESS TESTS FOR FIGURE 7.13:  STRONG TIES AND USE OF INTERNET DURING REVOLUTIONS--ARAB REVS ONLY
* =============================================================================
* Egypt
* checkrob command
* checkrob 2 3 ch7fig7_13a.txt:  mlogit egpartic5 newage newage2  gender frpart intnetinrev if country==2 [pw=WT], rrr
* 	Reworked results can be found in the Excel file checkrob.results.chapter7.xlsx,
*		under the Robustnesstests/Outputfiles directory
*	RESULT:  All patterns of significance stable (with exception of newage and newage2, which are variously insignificant); all signs remain stable
mlogit egpartic5 newage newage2  gender frpart intnetinrev if country==2 [pw=WT], rrr vce(robust)
*	RESULT:  No changes, except newage marginally significant at the .10 level
* Bootstrapped standard errors
mlogit egpartic5 c.newage##c.newage  gender frpart intnetinrev if country==2, rrr vce(bootstrap, bca seed(1234) rep(1000))
estat bootstrap, all
* 	RESULT:  No changes
* Testing for collinearity
collin gender newage frpart intnetinrev if country==2
*	RESULT:  tolerances are all > .5
* Tunisia
* checkrob command
* checkrob 1 3 ch7fig7_13b.txt: mlogit tpartic4 gender newage  frpart intnetinrev if country==10 [pw=WT], rrr
* 	Reworked results can be found in the Excel file checkrob.results.chapter7.xlsx,
*		under the Robustnesstests/Outputfiles directory
*	RESULT:  All patterns of significance stable and significant; all signs stable
* Robust standard errors
mlogit tpartic4 gender newage  frpart intnetinrev if country==10 [pw=WT], rrr vce(robust)
*	RESULT:  No changes
* Bootstrapped standard errors
mlogit tpartic4 gender newage  frpart intnetinrev if country==10, rrr vce(bootstrap, bca seed(1234) rep(1000))
estat bootstrap, all
*	RESULT:  No changes
* Testing for collinearity
collin gender newage frpart intnetinrev if country==10
*	RESULT:  tolerances are all > .5


log close

clear
